#include "internal.h"

/*
 * When switching to -deadline, we may overload the rq, then
 * we try to push someone off, if possible.
 */
static void switched_to_dl(struct rq *rq, struct task_struct *p)
{
    cancel_inactive_timer(&p->dl);

    /*
     * In case a task is setscheduled to SCHED_DEADLINE we need to keep
     * track of that on its cpuset (for correct bandwidth tracking).
     */
    inc_dl_tasks_cs(p);

    /* If p is not queued we will update its parameters at next wakeup. */
    if (!task_on_rq_queued(p))
    {
        add_rq_bw(&p->dl, &rq->dl);

        return;
    }

    if (rq->donor != p)
    {
        if (p->nr_cpus_allowed > 1 && rq->dl.overloaded)
            deadline_queue_push_tasks(rq);
        if (dl_task(rq->donor))
            wakeup_preempt_dl(rq, p, 0);
        else
            resched_curr(rq);
    }
    else
    {
        update_dl_rq_load_avg(rq_clock_pelt(rq), rq, 0);
    }
}
